from PyQt5.QtCore import QTime, QTimer
from PyQt5.QtWidgets import QStatusBar, QLabel


class Status():
    def __init__(self,canvas):
        self.canvas = canvas
        self.__ui()
        self.__gsp()
        self.__clock()

    def __ui(self):
        # 状态栏：显示坐标和系统时间
        self.status_bar = QStatusBar()
        self.status_bar.setStyleSheet("""
                   QStatusBar {
                       background-color: #E0E0E0;
                       border-top: 1px solid #C0C0C0;
                       padding: 0 5px;
                   }
               """)

        self.coord_label = QLabel("坐标：经度 0.000000, 纬度 0.000000")
        self.coord_label.setStyleSheet("""
                   QLabel {
                       font-family: Arial;
                       font-size: 10pt;
                       color: #000000;
                       padding: 0 10px;
                   }
               """)

        self.time_label = QLabel("系统时间: 00:00:00")
        self.time_label.setStyleSheet("""
                   QLabel {
                       font-family: Arial;
                       font-size: 10pt;
                       color: #000000;
                       padding: 0 10px;
                   }
               """)

        self.status_bar.addPermanentWidget(self.coord_label, 1)
        self.status_bar.addPermanentWidget(self.time_label, 0)

    def get(self):
        return self.status_bar

    def __gsp(self):
        # 连接鼠标坐标信号
        self.canvas.xyCoordinates.connect(self.__show_coordinates)

    def __show_coordinates(self, point):
        # 显示精确坐标
        self.coord_label.setText(f"坐标：经度 {point.x():.6f}, 纬度 {point.y():.6f}")

    def __clock(self):
        # 定时器更新时间
        self.timer = QTimer()
        self.timer.timeout.connect(self.__update_time)
        self.timer.start(1000)

    def __update_time(self):
        # 更新时间显示
        current_time = QTime.currentTime().toString("hh:mm:ss")
        self.time_label.setText(f"系统时间: {current_time}")
